package my.com.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

/**
 * 响应数据
 *  getWriter()    字符输出流(输出字符串)
 *  getOutStream() 字节输出流(输出一切数据)
 *
 *  两种流不可以同时使用
 */


@WebServlet("/s01")
public class Servlet01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Servlet01....");
        /**
         * getWriter()    字符输出流(输出字符串)
         */
        //获取字符输出流
        //PrintWriter writer = resp.getWriter();
        //输出流
        //writer.write("hello");

        //getOutStream() 字节输出流(输出一切数据)
        ServletOutputStream out = resp.getOutputStream();
        out.write("hi".getBytes(StandardCharsets.UTF_8));
    }
}